﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;

namespace WebApplication1
{
    [Serializable]
    public class 结构分级Data
    {

        public const string IDField = "@ID";

        public const string PRIMARYKEY_Field = @"ID";

        public const string 中心IDField = "@中心ID";

        public const string 分局IDField = "@分局ID";

        public const string 名称Field = "@名称";

        public const string 地址Field = "@地址";

        public const string 备注Field = "@备注";

        public const string ISAVAILABLEField = "@IsAvailable";

        public const string CREATORField = "@Creator";

        public const string ADDTIMEField = "@AddTime";

        public const string UPDATETIMEField = "@UpdateTime";

        private Guid _ID;

        private Guid _中心ID;

        private Guid _分局ID;

        private String _名称;

        private String _地址;

        private String _备注;

        private Boolean _IsAvailable;

        private String _Creator;

        private DateTime _AddTime;

        private DateTime _UpdateTime;

        public Guid ID
        {
            get { return _ID; }
            set { _ID = value; }
        }
        public Guid 中心ID
        {
            get { return _中心ID; }
            set { _中心ID = value; }
        }
        public Guid 分局ID
        {
            get { return _分局ID; }
            set { _分局ID = value; }
        }
        public String 名称
        {
            get { return _名称; }
            set { _名称 = value; }
        }
        public String 地址
        {
            get { return _地址; }
            set { _地址 = value; }
        }
        public String 备注
        {
            get { return _备注; }
            set { _备注 = value; }
        }
        public Boolean IsAvailable
        {
            get { return _IsAvailable; }
            set { _IsAvailable = value; }
        }
        public String Creator
        {
            get { return _Creator; }
            set { _Creator = value; }
        }
        public DateTime AddTime
        {
            get { return _AddTime; }
            set { _AddTime = value; }
        }
        public DateTime UpdateTime
        {
            get { return _UpdateTime; }
            set { _UpdateTime = value; }
        }
        public 结构分级Data()
        {
            _ID = Guid.Empty;
            _中心ID = Guid.Empty;
            _分局ID = Guid.Empty;
            _名称 = "";
            _地址 = "";
            _备注 = "";
            _IsAvailable = true;
            _Creator = "";
            _AddTime = DateTime.Now;
            _UpdateTime = DateTime.Now;
        }
    }

    public class 结构分级DataFactory
    {
        public static 结构分级Data Construct(IDataReader reader)
        {
            结构分级Data data = new 结构分级Data();

            try { data.ID = (Guid)(reader["ID"]); }
            catch { }

            try { data.中心ID = (Guid)(reader["中心ID"]); }
            catch { }

            try { data.分局ID = (Guid)(reader["分局ID"]); }
            catch { }

            try { data.名称 = Convert.ToString(reader["名称"]); }
            catch { }

            try { data.地址 = Convert.ToString(reader["地址"]); }
            catch { }

            try { data.备注 = Convert.ToString(reader["备注"]); }
            catch { }

            try { data.IsAvailable = Convert.ToBoolean(reader["IsAvailable"]); }
            catch { }

            try { data.Creator = Convert.ToString(reader["Creator"]); }
            catch { }

            try { data.AddTime = Convert.ToDateTime(reader["AddTime"]); }
            catch { }

            try { data.UpdateTime = Convert.ToDateTime(reader["UpdateTime"]); }
            catch { }

            return data;
        }
        public static Guid GetPrimaryKey(DataTable dt)
        {
            return GetPrimaryKey(dt, 0);
        }
        public static Guid GetPrimaryKey(DataTable dt, int rowIndex)
        {
            Guid PrimaryKey = Guid.Empty;

            if (dt.Rows.Count < rowIndex + 1)

                return Guid.Empty;

            DataRow dr = dt.Rows[rowIndex];

            if (dr == null)

                return Guid.Empty;

            try { PrimaryKey = (Guid)(dr[结构分级Data.PRIMARYKEY_Field]); }
            catch { }

            return PrimaryKey;
        }
        public static 结构分级Data Construct(DataTable dt)
        {
            return Construct(dt, 0);
        }
        public static 结构分级Data Construct(DataTable dt, int rowIndex)
        {
            结构分级Data data = new 结构分级Data();

            if (dt.Rows.Count < rowIndex + 1)

                return null;

            DataRow dr = dt.Rows[rowIndex];

            if (dr == null)

                return null;

            try { data.ID = new Guid(dr["ID"].ToString()); }
            catch { }

            try { data.中心ID = new Guid(dr["中心ID"].ToString()); }
            catch { }

            try { data.分局ID = new Guid(dr["分局ID"].ToString()); }
            catch { }

            try { data.名称 = Convert.ToString(dr["名称"]); }
            catch { }

            try { data.地址 = Convert.ToString(dr["地址"]); }
            catch { }

            try { data.备注 = Convert.ToString(dr["备注"]); }
            catch { }

            try { data.IsAvailable = Convert.ToBoolean(dr["IsAvailable"]); }
            catch { }

            try { data.Creator = Convert.ToString(dr["Creator"]); }
            catch { }

            try { data.AddTime = Convert.ToDateTime(dr["AddTime"]); }
            catch { }

            try { data.UpdateTime = Convert.ToDateTime(dr["UpdateTime"]); }
            catch { }

            return data;
        }
        
        public static 结构分级Data Construct(DataRow dr)
        {
            结构分级Data data = new 结构分级Data();

            try { data.ID = new Guid(dr["ID"].ToString()); }
            catch { }

            try { data.中心ID = new Guid(dr["中心ID"].ToString()); }
            catch { }

            try { data.分局ID = new Guid(dr["分局ID"].ToString()); }
            catch { }

            try { data.名称 = Convert.ToString(dr["名称"]); }
            catch { }

            try { data.地址 = Convert.ToString(dr["地址"]); }
            catch { }

            try { data.备注 = Convert.ToString(dr["备注"]); }
            catch { }

            try { data.IsAvailable = Convert.ToBoolean(dr["IsAvailable"]); }
            catch { }

            try { data.Creator = Convert.ToString(dr["Creator"]); }
            catch { }

            try { data.AddTime = Convert.ToDateTime(dr["AddTime"]); }
            catch { }

            try { data.UpdateTime = Convert.ToDateTime(dr["UpdateTime"]); }
            catch { }

            return data;
        }
        public static Guid GetPrimaryKey(DataRow dr)
        {
            Guid PrimaryKey = Guid.Empty;

            try { PrimaryKey = (Guid)(dr[结构分级Data.PRIMARYKEY_Field]); }
            catch { }
            return PrimaryKey;
        }

    }
    public class 结构分级DataDBOption
    {
        public static int Insert_zx(结构分级Data d)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into 结构分级 (");
            sql.Append("名称, ");
            sql.Append("地址, ");
            sql.Append("备注, ");
            sql.Append("IsAvailable, ");
            sql.Append("Creator, ");
            sql.Append("AddTime, ");
            sql.Append("UpdateTime");
            sql.Append(") values (");          
            sql.Append("'");
            sql.Append(d.名称.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.地址.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.备注.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("");
            if (d.IsAvailable)
                sql.Append("1");
            else
                sql.Append("0");
            sql.Append("");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.Creator.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.AddTime.ToString("yyyy-MM-dd hh:mm:ss"));
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.UpdateTime.ToString("yyyy-MM-dd hh:mm:ss"));
            sql.Append("'");
            sql.Append(")");
            return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
        }
        public static int Insert_fj(结构分级Data d)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into 结构分级 (");
            sql.Append("中心ID, ");
            sql.Append("名称, ");
            sql.Append("地址, ");
            sql.Append("备注, ");
            sql.Append("IsAvailable, ");
            sql.Append("Creator, ");
            sql.Append("AddTime, ");
            sql.Append("UpdateTime");
            sql.Append(") values (");
            sql.Append("'");
            sql.Append(d.中心ID.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.名称.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.地址.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.备注.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("");
            if (d.IsAvailable)
                sql.Append("1");
            else
                sql.Append("0");
            sql.Append("");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.Creator.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.AddTime.ToString("yyyy-MM-dd hh:mm:ss"));
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.UpdateTime.ToString("yyyy-MM-dd hh:mm:ss"));
            sql.Append("'");
            sql.Append(")");
            return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
        }
        public static int Insert(结构分级Data d)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into 结构分级 (");
            sql.Append("中心ID, ");
            sql.Append("分局ID, ");
            sql.Append("名称, ");
            sql.Append("地址, ");
            sql.Append("备注, ");
            sql.Append("IsAvailable, ");
            sql.Append("Creator, ");
            sql.Append("AddTime, ");
            sql.Append("UpdateTime");
            sql.Append(") values (");
            sql.Append("'");
            sql.Append(d.中心ID.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.分局ID.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.名称.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.地址.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.备注.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("");
            if (d.IsAvailable)
                sql.Append("1");
            else
                sql.Append("0");
            sql.Append("");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.Creator.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.AddTime.ToString("yyyy-MM-dd hh:mm:ss"));
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.UpdateTime.ToString("yyyy-MM-dd hh:mm:ss"));
            sql.Append("'");
            sql.Append(")");
            return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
        }
        public static int Update_zx(结构分级Data d)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("update 结构分级 set ");            
            sql.Append("地址=");
            sql.Append("'");
            sql.Append(d.地址.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("备注=");
            sql.Append("'");
            sql.Append(d.备注.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("IsAvailable=");
            sql.Append("");
            if (d.IsAvailable)
                sql.Append("1");
            else
                sql.Append("0");
            sql.Append("");
            sql.Append(", ");            
            sql.Append("UpdateTime=");
            sql.Append("'");
            sql.Append(d.UpdateTime.ToString("yyyy-MM-dd hh:mm:ss"));
            sql.Append("'");
            sql.Append(" where ID='");
            sql.Append(d.ID.ToString());
            sql.Append("'");
            return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
        }        
        public static int Update(结构分级Data d)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("update 结构分级 set ");
            sql.Append("中心ID=");
            sql.Append("'");
            sql.Append(d.中心ID.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("分局ID=");
            sql.Append("'");
            sql.Append(d.分局ID.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("名称=");
            sql.Append("'");
            sql.Append(d.名称.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("地址=");
            sql.Append("'");
            sql.Append(d.地址.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("备注=");
            sql.Append("'");
            sql.Append(d.备注.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("IsAvailable=");
            sql.Append("");
            if (d.IsAvailable)
                sql.Append("1");
            else
                sql.Append("0");
            sql.Append("");
            sql.Append(", ");
            sql.Append("Creator=");
            sql.Append("'");
            sql.Append(d.Creator.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("AddTime=");
            sql.Append("'");
            sql.Append(d.AddTime.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("UpdateTime=");
            sql.Append("'");
            sql.Append(d.UpdateTime.ToString());
            sql.Append("'");
            sql.Append(" where ID=");
            sql.Append(d.ID.ToString());
            return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
        }
        public static int Delete(结构分级Data d)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from 结构分级 ");
            sql.Append(" where ID='");
            sql.Append(d.ID.ToString());
            sql.Append("'");
            return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
        }
        public static DataTable DataTableSelect()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from 结构分级 ");
            return WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
        }
        public static DataTable DataTableSelect(结构分级Data d)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from 结构分级 where ID='");
            sql.Append(d.ID.ToString());
            sql.Append("'");
            return WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
        }
        public static DataSet DataSetSelect()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from 结构分级 ");
            return WFNetLib.ADO.SQLServerOP.DataSetSQL(sql.ToString());
        }
        public static SqlDataReader ReaderSelect(结构分级Data d)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from 结构分级 ");
            return WFNetLib.ADO.SQLServerOP.ReaderExecuteSQL(sql.ToString());
        }
    }
}